package com.controller;

import com.entity.RbacManager;
import com.entity.ResponseEntity;
import com.github.pagehelper.PageInfo;
import com.service.RbacManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/rbacManager")
public class RbacManaerController {
    @Autowired
    private RbacManagerService rbacManagerService;
    @GetMapping("/User/{startPage}/{pageSize}")
    public ResponseEntity findAll(@PathVariable int startPage,@PathVariable int pageSize){
        ResponseEntity all = rbacManagerService.findAll(startPage,pageSize);
        PageInfo info = new PageInfo<RbacManager>((List<RbacManager>) all.getData());
        all.setData(info);
        return all;
    }
    @GetMapping("/User/{id}")
    public ResponseEntity findOne(@PathVariable int id){
        return rbacManagerService.findOne(id);
    }
    @PostMapping("/User")
    public ResponseEntity add(@RequestBody RbacManager rbacManager){
        return rbacManagerService.addOne(rbacManager);
    }
    @DeleteMapping("/User/{id}")
    public ResponseEntity delete(@PathVariable int id){
        return rbacManagerService.deleteOne(id);
    }
    @PutMapping(value = "/User")
    public ResponseEntity updateOne(@RequestBody RbacManager rbacManager){
        System.out.println("rbacManager = " + rbacManager);
        return rbacManagerService.updateOne(rbacManager);
    }
    @GetMapping("/User/{startPage}/{pageSize}/{name}")
    public ResponseEntity findByName(@PathVariable int startPage,@PathVariable int pageSize,@PathVariable String name){
        ResponseEntity all = rbacManagerService.findByName(startPage,pageSize,name);
        PageInfo info = new PageInfo<RbacManager>((List<RbacManager>) all.getData());
        all.setData(info);
        return all;
    }
}
